<template>

  <div :xs="13" :sm="24" :md="20" :lg="24" >
    <el-dialog width="1200%" :title="title" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible">
      <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method==='view'"
        label-width="120px">
        <el-row :gutter="17">
          <el-col :span="23">
            <el-form-item label="案例类型" prop="anli.id" :rules="[
                 ]">
              <SelectTree model="nb" ref="anli" :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"
                url="/treess/yjyTree/treeData" :value="inputForm.anli.id" :clearable="true" :accordion="true" @getValue="(value) => {inputForm.anli.id=value}" />
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="案件名称" prop="remarks" :rules="[
                 ]">
              <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"></el-input>
            </el-form-item>
          </el-col>


        </el-row>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
        <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
      </span>
    </el-dialog>
    <YjyFuelevenForm ref="yjyFuelevenForm" @addRow="saveYjyFuelevenRow(arguments)"></YjyFuelevenForm>
    <YjyFuFiveForm ref="yjyFuFiveForm" @addRow="saveYjyFuFiveRow(arguments)"></YjyFuFiveForm>
    <YjyFuFourForm ref="yjyFuFourForm" @addRow="saveYjyFuFourRow(arguments)"></YjyFuFourForm>
    <YjyFuJkForm ref="yjyFuJkForm" @addRow="saveYjyFuJkRow(arguments)"></YjyFuJkForm>
    <YjyFuOneForm ref="yjyFuOneForm" @addRow="saveYjyFuOneRow(arguments)"></YjyFuOneForm>
    <YjyFussForm ref="yjyFussForm" @addRow="saveYjyFussRow(arguments)"></YjyFussForm>
    <YjyFuTwoForm ref="yjyFuTwoForm" @addRow="saveYjyFuTwoRow(arguments)"></YjyFuTwoForm>
    <YjyThirteenForm ref="yjyThirteenForm" @addRow="saveYjyThirteenRow(arguments)"></YjyThirteenForm>
    <YjyFuThreeForm ref="yjyFuThreeForm" @addRow="saveYjyFuThreeRow(arguments)"></YjyFuThreeForm>
    <YjyLastForm ref="yjyLastForm" @addRow="saveYjyLastRow(arguments)"></YjyLastForm>
    <YjyRecoverForm ref="yjyRecoverForm" @addRow="saveYjyRecoverRow(arguments)"></YjyRecoverForm>

  </div>
</template>

<script>
  import YjyFuelevenForm from './YjyFuelevenForm'
  import YjyFuFiveForm from './YjyFuFiveForm'
  import YjyFuFourForm from './YjyFuFourForm'
  import YjyFuJkForm from './YjyFuJkForm'
  import YjyFuOneForm from './YjyFuOneForm'
  import YjyFussForm from './YjyFussForm'
  import YjyFuTwoForm from './YjyFuTwoForm'
  import YjyThirteenForm from './YjyThirteenForm'
  import YjyFuThreeForm from './YjyFuThreeForm'
  import YjyLastForm from './YjyLastForm'
  import YjyRecoverForm from './YjyRecoverForm'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        yjyShoujiTab: '0',
        names: 'addYjyFuelevenRow',
        inputForm: {
          id: '',
          yjyFuelevenList: [],
          yjyFuFiveList: [],
          yjyFuFourList: [],
          yjyFuJkList: [],
          yjyFuOneList: [],
          yjyFussList: [],
          yjyFuTwoList: [],
          yjyThirteenList: [],
          yjyFuThreeList: [],
          yjyLastList: [],
          yjyRecoverList: [],
          anli: {
            id: ''
          },
          remarks: ''
        },
        nb: ''
      }
    },
    components: {
      SelectTree,
      YjyFuelevenForm,
      YjyFuFiveForm,
      YjyFuFourForm,
      YjyFuJkForm,
      YjyFuOneForm,
      YjyFussForm,
      YjyFuTwoForm,
      YjyThirteenForm,
      YjyFuThreeForm,
      YjyLastForm,
      YjyRecoverForm
    },
    watch: {
      'inputForm.anli.id': function (newVal, oldVal) {
        if (newVal === 'bf9867252554474489cc00d481e1d9b6') {
          this.addYjyFuOneRow()
        } else if (newVal === '062791a258dc49ac9f5d96ce8f1fba6a') {
          this.addYjyFuTwoRow()
        } else if (newVal === 'aade6bc59a7a457693ec21884e27ff5e') {
          this.addYjyFuThreeRow()
        } else if (newVal === 'b3359a5c61f1413a940a228bce9175d8') {
          this.addYjyFuFourRow()
        } else if (newVal === '9941bfb4e1ad45958290610c61432e45') {
          this.addYjyFuFiveRow()
        } else if (newVal === '3aa99cdda6dd4b5699b1fabf0bd35efc') {
          this.addYjyFussRow()
        } else if (newVal === 'fd6325fbf0764d1392f4b77202c4c7ba') {
          this.addYjyFuJkRow()
        } else if (newVal === 'c74bd7d28b314793a8d9f60cf74bab5d') {
          this.addYjyRecoverRow()
        } else if (newVal === '66c72e0fb89348928525eed47697c61e') {
          this.addYjyFuelevenRow()
        } else if (newVal === '29925d2a5ee04d8f8ff47f7d3422b0d4') {
          this.addYjyThirteenRow()
        } else if (newVal === '2eb7d65deb4540d7b97e6be2dc9f76f9') {
          this.addYjyLastRow()
        }
      }
    },
    methods: {
      init (method, id) {
        this.method = method
        if (method === 'add') {
          this.title = `新建1`
        } else if (method === 'edit') {
          this.title = '修改1'
        } else if (method === 'view') {
          this.title = '查看1'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.id = id
          this.yjyShoujiTab = '0'
          this.inputForm.yjyFuelevenList = []
          this.inputForm.yjyFuFiveList = []
          this.inputForm.yjyFuFourList = []
          this.inputForm.yjyFuJkList = []
          this.inputForm.yjyFuOneList = []
          this.inputForm.yjyFussList = []
          this.inputForm.yjyFuTwoList = []
          this.inputForm.yjyThirteenList = []
          this.inputForm.yjyFuThreeList = []
          this.inputForm.yjyLastList = []
          this.inputForm.yjyRecoverList = []
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/handlingcases/yjyShouji/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({
              data
            }) => {
              this.inputForm = this.recover(this.inputForm, data.yjyShouji)
              this.loading = false
            })
          }
        })
      },
      saveYjyFuelevenRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFuelevenList.push(child[1])
        } else {
          this.inputForm.yjyFuelevenList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFuelevenList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFuelevenRow (child) {
        this.$refs.yjyFuelevenForm.init('add')
      },
      viewYjyFuelevenRow (child) {
        this.$refs.yjyFuelevenForm.init('view', child)
      },
      editYjyFuelevenRow (child) {
        this.$refs.yjyFuelevenForm.init('edit', child)
      },
      delYjyFuelevenRow (child) {
        this.inputForm.yjyFuelevenList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFuelevenList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFuelevenList.splice(index, 1, item)
          }
        })
      },
      saveYjyFuFiveRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFuFiveList.push(child[1])
        } else {
          this.inputForm.yjyFuFiveList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFuFiveList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFuFiveRow (child) {
        this.$refs.yjyFuFiveForm.init('add')
      },
      viewYjyFuFiveRow (child) {
        this.$refs.yjyFuFiveForm.init('view', child)
      },
      editYjyFuFiveRow (child) {
        this.$refs.yjyFuFiveForm.init('edit', child)
      },
      delYjyFuFiveRow (child) {
        this.inputForm.yjyFuFiveList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFuFiveList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFuFiveList.splice(index, 1, item)
          }
        })
      },
      saveYjyFuFourRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFuFourList.push(child[1])
        } else {
          this.inputForm.yjyFuFourList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFuFourList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFuFourRow (child) {
        this.$refs.yjyFuFourForm.init('add')
      },
      viewYjyFuFourRow (child) {
        this.$refs.yjyFuFourForm.init('view', child)
      },
      editYjyFuFourRow (child) {
        this.$refs.yjyFuFourForm.init('edit', child)
      },
      delYjyFuFourRow (child) {
        this.inputForm.yjyFuFourList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFuFourList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFuFourList.splice(index, 1, item)
          }
        })
      },
      saveYjyFuJkRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFuJkList.push(child[1])
        } else {
          this.inputForm.yjyFuJkList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFuJkList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFuJkRow (child) {
        this.$refs.yjyFuJkForm.init('add')
      },
      viewYjyFuJkRow (child) {
        this.$refs.yjyFuJkForm.init('view', child)
      },
      editYjyFuJkRow (child) {
        this.$refs.yjyFuJkForm.init('edit', child)
      },
      delYjyFuJkRow (child) {
        this.inputForm.yjyFuJkList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFuJkList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFuJkList.splice(index, 1, item)
          }
        })
      },
      saveYjyFuOneRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFuOneList.push(child[1])
        } else {
          this.inputForm.yjyFuOneList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFuOneList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFuOneRow (child) {
        this.$refs.yjyFuOneForm.init('add')
      },
      viewYjyFuOneRow (child) {
        this.$refs.yjyFuOneForm.init('view', child)
      },
      editYjyFuOneRow (child) {
        this.$refs.yjyFuOneForm.init('edit', child)
      },
      delYjyFuOneRow (child) {
        this.inputForm.yjyFuOneList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFuOneList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFuOneList.splice(index, 1, item)
          }
        })
      },
      saveYjyFussRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFussList.push(child[1])
        } else {
          this.inputForm.yjyFussList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFussList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFussRow (child) {
        this.$refs.yjyFussForm.init('add')
      },
      viewYjyFussRow (child) {
        this.$refs.yjyFussForm.init('view', child)
      },
      editYjyFussRow (child) {
        this.$refs.yjyFussForm.init('edit', child)
      },
      delYjyFussRow (child) {
        this.inputForm.yjyFussList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFussList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFussList.splice(index, 1, item)
          }
        })
      },
      saveYjyFuTwoRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFuTwoList.push(child[1])
        } else {
          this.inputForm.yjyFuTwoList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFuTwoList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFuTwoRow (child) {
        this.$refs.yjyFuTwoForm.init('add')
      },
      viewYjyFuTwoRow (child) {
        this.$refs.yjyFuTwoForm.init('view', child)
      },
      editYjyFuTwoRow (child) {
        this.$refs.yjyFuTwoForm.init('edit', child)
      },
      delYjyFuTwoRow (child) {
        this.inputForm.yjyFuTwoList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFuTwoList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFuTwoList.splice(index, 1, item)
          }
        })
      },
      saveYjyThirteenRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyThirteenList.push(child[1])
        } else {
          this.inputForm.yjyThirteenList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyThirteenList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyThirteenRow (child) {
        this.$refs.yjyThirteenForm.init('add')
      },
      viewYjyThirteenRow (child) {
        this.$refs.yjyThirteenForm.init('view', child)
      },
      editYjyThirteenRow (child) {
        this.$refs.yjyThirteenForm.init('edit', child)
      },
      delYjyThirteenRow (child) {
        this.inputForm.yjyThirteenList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyThirteenList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyThirteenList.splice(index, 1, item)
          }
        })
      },
      saveYjyFuThreeRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyFuThreeList.push(child[1])
        } else {
          this.inputForm.yjyFuThreeList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyFuThreeList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyFuThreeRow (child) {
        this.$refs.yjyFuThreeForm.init('add')
      },
      viewYjyFuThreeRow (child) {
        this.$refs.yjyFuThreeForm.init('view', child)
      },
      editYjyFuThreeRow (child) {
        this.$refs.yjyFuThreeForm.init('edit', child)
      },
      delYjyFuThreeRow (child) {
        this.inputForm.yjyFuThreeList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyFuThreeList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyFuThreeList.splice(index, 1, item)
          }
        })
      },
      saveYjyLastRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyLastList.push(child[1])
        } else {
          this.inputForm.yjyLastList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyLastList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyLastRow (child) {
        this.$refs.yjyLastForm.init('add')
      },
      viewYjyLastRow (child) {
        this.$refs.yjyLastForm.init('view', child)
      },
      editYjyLastRow (child) {
        this.$refs.yjyLastForm.init('edit', child)
      },
      delYjyLastRow (child) {
        this.inputForm.yjyLastList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyLastList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyLastList.splice(index, 1, item)
          }
        })
      },
      saveYjyRecoverRow (child) {
        if (child[0] === '') {
          this.inputForm.yjyRecoverList.push(child[1])
        } else {
          this.inputForm.yjyRecoverList.forEach((item, index) => {
            if (item === child[0]) {
              this.inputForm.yjyRecoverList.splice(index, 1, child[1])
            }
          })
        }
      },
      addYjyRecoverRow (child) {
        this.$refs.yjyRecoverForm.init('add')
      },
      viewYjyRecoverRow (child) {
        this.$refs.yjyRecoverForm.init('view', child)
      },
      editYjyRecoverRow (child) {
        this.$refs.yjyRecoverForm.init('edit', child)
      },
      delYjyRecoverRow (child) {
        this.inputForm.yjyRecoverList.forEach((item, index) => {
          if (item === child && item.id === '') {
            this.inputForm.yjyRecoverList.splice(index, 1)
          } else if (item === child) {
            item.delFlag = '1'
            this.inputForm.yjyRecoverList.splice(index, 1, item)
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/handlingcases/yjyShouji/save`,
              method: 'post',
              data: this.inputForm
            }).then(({
              data
            }) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>
